package dfd.diagram.providers;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

import dfd.DfdPackage;
import dfd.diagram.edit.parts.ActionActionNameEditPart;
import dfd.diagram.edit.parts.AndNameEditPart;
import dfd.diagram.edit.parts.EndNameEditPart;
import dfd.diagram.edit.parts.OrNameEditPart;
import dfd.diagram.edit.parts.ProcessNameEditPart;
import dfd.diagram.edit.parts.StartNameEditPart;
import dfd.diagram.edit.parts.StorageNameEditPart;
import dfd.diagram.edit.parts.TransitionNameEditPart;
import dfd.diagram.edit.parts.XorNameEditPart;
import dfd.diagram.parsers.MessageFormatParser;
import dfd.diagram.part.DfdVisualIDRegistry;

/**
 * @generated
 */
public class DfdParserProvider extends AbstractProvider implements
		IParserProvider {

	/**
	 * @generated
	 */
	private IParser andName_5001Parser;

	/**
	 * @generated
	 */
	private IParser getAndName_5001Parser() {
		if (andName_5001Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			andName_5001Parser = parser;
		}
		return andName_5001Parser;
	}

	/**
	 * @generated
	 */
	private IParser processName_5002Parser;

	/**
	 * @generated
	 */
	private IParser getProcessName_5002Parser() {
		if (processName_5002Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			processName_5002Parser = parser;
		}
		return processName_5002Parser;
	}

	/**
	 * @generated
	 */
	private IParser xorName_5003Parser;

	/**
	 * @generated
	 */
	private IParser getXorName_5003Parser() {
		if (xorName_5003Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			xorName_5003Parser = parser;
		}
		return xorName_5003Parser;
	}

	/**
	 * @generated
	 */
	private IParser startName_5004Parser;

	/**
	 * @generated
	 */
	private IParser getStartName_5004Parser() {
		if (startName_5004Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			startName_5004Parser = parser;
		}
		return startName_5004Parser;
	}

	/**
	 * @generated
	 */
	private IParser orName_5005Parser;

	/**
	 * @generated
	 */
	private IParser getOrName_5005Parser() {
		if (orName_5005Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			orName_5005Parser = parser;
		}
		return orName_5005Parser;
	}

	/**
	 * @generated
	 */
	private IParser endName_5006Parser;

	/**
	 * @generated
	 */
	private IParser getEndName_5006Parser() {
		if (endName_5006Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			endName_5006Parser = parser;
		}
		return endName_5006Parser;
	}

	/**
	 * @generated
	 */
	private IParser storageName_5007Parser;

	/**
	 * @generated
	 */
	private IParser getStorageName_5007Parser() {
		if (storageName_5007Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getNode_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			storageName_5007Parser = parser;
		}
		return storageName_5007Parser;
	}

	/**
	 * @generated
	 */
	private IParser actionActionName_5009Parser;

	/**
	 * @generated
	 */
	private IParser getActionActionName_5009Parser() {
		if (actionActionName_5009Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getAction_ActionName() };
			MessageFormatParser parser = new MessageFormatParser(features);
			actionActionName_5009Parser = parser;
		}
		return actionActionName_5009Parser;
	}

	/**
	 * @generated
	 */
	private IParser transitionName_6001Parser;

	/**
	 * @generated
	 */
	private IParser getTransitionName_6001Parser() {
		if (transitionName_6001Parser == null) {
			EAttribute[] features = new EAttribute[] { DfdPackage.eINSTANCE
					.getTransition_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			transitionName_6001Parser = parser;
		}
		return transitionName_6001Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case AndNameEditPart.VISUAL_ID:
			return getAndName_5001Parser();
		case ProcessNameEditPart.VISUAL_ID:
			return getProcessName_5002Parser();
		case XorNameEditPart.VISUAL_ID:
			return getXorName_5003Parser();
		case StartNameEditPart.VISUAL_ID:
			return getStartName_5004Parser();
		case OrNameEditPart.VISUAL_ID:
			return getOrName_5005Parser();
		case EndNameEditPart.VISUAL_ID:
			return getEndName_5006Parser();
		case StorageNameEditPart.VISUAL_ID:
			return getStorageName_5007Parser();
		case ActionActionNameEditPart.VISUAL_ID:
			return getActionActionName_5009Parser();
		case TransitionNameEditPart.VISUAL_ID:
			return getTransitionName_6001Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(DfdVisualIDRegistry.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(DfdVisualIDRegistry.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (DfdElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
